package com.zking.ssm.DYM.controller;

import com.zking.ssm.DYM.model.HotelCouponsBreakfast;
import com.zking.ssm.DYM.service.IHotelCouponsBreakfaseService;
import com.zking.ssm.util.JsonData;
import com.zking.ssm.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author XXXXX
 * @Date 2021/01/23 15:17
 */
@Controller
@RequestMapping("/hotelCouponsBreakfast")
public class HotelCouponsBreakfastController {
    @Autowired
    private IHotelCouponsBreakfaseService hotelCouponsBreakfaseService;

    @ModelAttribute
    public void init(Model model) {
        System.out.println("init");
        HotelCouponsBreakfast hotelCouponsBreakfast = new HotelCouponsBreakfast();
        model.addAttribute("hotelCouponsBreakfast", hotelCouponsBreakfast);
    }

    //添加
    @RequestMapping("/toAddHotelCouponsBreakfast")
    public String toAddHotelCouponsBreakfast(Model model) {
        System.out.println("toAddHotelCouponsBreakfast");
        return "addHotelCouponsBreakfast";
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(HotelCouponsBreakfast hotelCouponsBreakfast) {
        System.out.println("toAddHotelCouponsBreakfast");
        hotelCouponsBreakfaseService.insert(hotelCouponsBreakfast);
        return "redirect:toAddHotelCouponsBreakfast";
    }

    //修改
    @RequestMapping("/updateHotelCouponsBreakfast")
    public String toUpdateHotelCouponsBreakfast(@PathVariable("id") Long id, Model model) {
        model.addAttribute("updateHotelCouponsBreakfast", hotelCouponsBreakfaseService.selectByPrimaryKey(1L));
        return "updateHotelCouponsBreakfast";
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(HotelCouponsBreakfast hotelCouponsBreakfast) {
        hotelCouponsBreakfaseService.updateByPrimaryKey(hotelCouponsBreakfast);
        return "redirect:updateHotelCouponsBreakfast";
    }

    //删除
    @RequestMapping(value = "/deleteHotelCouponsBreakfast")
    @ResponseBody
    public String deleteHotelCouponsBreakfast(Long id) {
        hotelCouponsBreakfaseService.deleteByPrimaryKey(id);
        System.out.println(id);
        return "redirect:HotelCouponsBreakfast";
//        return "删除成功";
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public JsonData list(HotelCouponsBreakfast hotelCouponsBreakfast, PageBean pageBean) {
        System.out.println("list");
        List<HotelCouponsBreakfast> hotelCouponsBreakfastList = hotelCouponsBreakfaseService.list(hotelCouponsBreakfast, pageBean);
        System.out.println("集合:" + hotelCouponsBreakfastList);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setPage(pageBean.getPage());
        jsonData.setRows(pageBean.getRows());
        jsonData.setTotal(pageBean.getTotal());
        jsonData.setMessage("查询成功");
        jsonData.setResult(hotelCouponsBreakfastList);
        return jsonData;
    }

    @RequestMapping(value = "/get")
    @ResponseBody
    public JsonData get(HotelCouponsBreakfast hotelCouponsBreakfast) {
        HotelCouponsBreakfast h = hotelCouponsBreakfaseService.selectByPrimaryKey(hotelCouponsBreakfast.getId());
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("查询成功");
        jsonData.setResult(h);
        return jsonData;
    }


}
